
package com.insigma.business.qrcode.soldier._bff.impl;


import cn.hutool.core.bean.BeanUtil;

import com.insigma.business.qrcode.common.template.BasePagingResponse;
import com.insigma.business.qrcode.common.util.BizCheckUtil;
import com.insigma.business.qrcode.common.util.SessionUtils;
import com.insigma.business.qrcode.common.vo.BaseDeleteRequest;
import com.insigma.business.qrcode.common.vo.BaseResponse;
import com.insigma.business.qrcode.soldier.dto.PlacementThroughTrainApplyInfoDTO;
import com.insigma.business.qrcode.soldier.dto.PlacementThroughTrainApplyInfoSearchRequest;
import com.insigma.business.qrcode.soldier.dto.gov.BaseProviderImpl;
import com.insigma.business.qrcode.common.template.area.ScenarioCodeEnum;
import com.insigma.business.qrcode.common.template.area.ServiceCallback;
import com.insigma.business.qrcode.soldier.request.BaseGetRequest;
import com.insigma.business.qrcode.soldier.request.PlacementThroughTrainApplyInfoInsertRequest;
import com.insigma.business.qrcode.soldier.request.PlacementThroughTrainApplyInfoUpdateRequest;
import com.insigma.business.qrcode.soldier._bff.PlacementThroughTrainApplyInfoBFFProvider;
import com.insigma.business.qrcode.soldier._consumer.PlacementThroughTrainApplyInfoConsumer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@Service
@Component("placementThroughTrainApplyInfoBFFProvider")
public class PlacementThroughTrainApplyInfoBFFProviderImpl extends BaseProviderImpl implements PlacementThroughTrainApplyInfoBFFProvider {

    @Autowired
    private PlacementThroughTrainApplyInfoConsumer placementThroughTrainApplyInfoConsumer;


    @Override
    public BasePagingResponse<List<PlacementThroughTrainApplyInfoDTO>> searchPlacementThroughTrainApplyInfo(final PlacementThroughTrainApplyInfoSearchRequest searchRequest) {

        final BasePagingResponse<List<PlacementThroughTrainApplyInfoDTO>> basePagingResponse = new BasePagingResponse<>();
        serviceTemplate.execute(basePagingResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(searchRequest, "查询分页PlacementThroughTrainApplyInfo的请求参数不能为空");
            }

            @Override
            public void executeService() {



                BasePagingResponse<List<PlacementThroughTrainApplyInfoDTO>> listBasePagingResponse = placementThroughTrainApplyInfoConsumer.searchPlacementThroughTrainApplyInfo(searchRequest);
                BeanUtil.copyProperties(listBasePagingResponse, basePagingResponse);
             }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.PLACEMENT_THROUGH_TRAIN_APPLY_INFO_SEARCH;
            }
        });

        return basePagingResponse;
    }



    @Override
    public BaseResponse<PlacementThroughTrainApplyInfoDTO> getPlacementThroughTrainApplyInfo(final BaseGetRequest baseGetRequest){

        final BaseResponse<PlacementThroughTrainApplyInfoDTO> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(baseGetRequest, "获取单条PlacementThroughTrainApplyInfo的请求参数不能为空");
                BizCheckUtil.checkNotBlank((String)baseGetRequest.getId(), "id不能为空");
            }

            @Override
            public void executeService() {
                final BaseResponse<PlacementThroughTrainApplyInfoDTO> placementThroughTrainApplyInfoResponse = placementThroughTrainApplyInfoConsumer.getPlacementThroughTrainApplyInfo(baseGetRequest);
                BeanUtil.copyProperties(placementThroughTrainApplyInfoResponse, baseResponse);
            }
            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.PLACEMENT_THROUGH_TRAIN_APPLY_INFO_GET;
            }
        });
        return baseResponse;
    }


    @Override
    public BaseResponse<String> insertPlacementThroughTrainApplyInfo(final PlacementThroughTrainApplyInfoInsertRequest insertRequest){

        final BaseResponse<String> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(transactionTemplate, baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(insertRequest, "新增PlacementThroughTrainApplyInfo的请求参数不能为空");
            }
            @Override
            public void executeService() {
                insertRequest.setSoldierId(SessionUtils.getSoldierUserId());
                BaseResponse<String> placementThroughTrainApplyInfoResponse = placementThroughTrainApplyInfoConsumer.insertPlacementThroughTrainApplyInfo(insertRequest);
                BeanUtil.copyProperties(placementThroughTrainApplyInfoResponse, baseResponse);
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.PLACEMENT_THROUGH_TRAIN_APPLY_INFO_INSERT;
            }
        });
        return baseResponse;
    }

    @Override
    public BaseResponse<PlacementThroughTrainApplyInfoDTO> getMyApplyInfo() {

        return placementThroughTrainApplyInfoConsumer.getMyApplyInfo(SessionUtils.getSoldierUserId());
    }

    @Override
    public BaseResponse<Integer> checkPlacementThroughTrainApplyInfo(PlacementThroughTrainApplyInfoUpdateRequest request) {

        BizCheckUtil.checkNotNull(request, "请求不能为空");
        BizCheckUtil.checkNotBlank(request.getId(), "id不能为空");
        BizCheckUtil.checkNotBlank(request.getStatus(), "id不能为空");

        SessionUtils.buildModifierOfGov(request);
        return placementThroughTrainApplyInfoConsumer.checkPlacementThroughTrainApplyInfo(request);
    }


    @Override
    public BaseResponse<Integer> updatePlacementThroughTrainApplyInfo(final PlacementThroughTrainApplyInfoUpdateRequest updateRequest){

        final BaseResponse<Integer> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(transactionTemplate, baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(updateRequest, "修改PlacementThroughTrainApplyInfo的请求参数不能为空");
                BizCheckUtil.checkNotBlank(updateRequest.getId(), "id不能为空");
                BizCheckUtil.checkNotBlank(updateRequest.getModifierId(),"操作人不能为空");
                BizCheckUtil.checkNotBlank(updateRequest.getModifierType(),"操作人类型不能为空");
            }
            @Override
            public void executeService() {
                BaseResponse<Integer> placementThroughTrainApplyInfoResponse = placementThroughTrainApplyInfoConsumer.updatePlacementThroughTrainApplyInfo(updateRequest);
                BeanUtil.copyProperties(placementThroughTrainApplyInfoResponse, baseResponse);
            }
            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.PLACEMENT_THROUGH_TRAIN_APPLY_INFO_UPDATE;
            }
        });
        return baseResponse;
    }


    @Override
    public BaseResponse<Integer> deletePlacementThroughTrainApplyInfo(final BaseDeleteRequest deleteRequest){

        final BaseResponse<Integer> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(transactionTemplate, baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(deleteRequest, "逻辑删除PlacementThroughTrainApplyInfo的请求参数不能为空");
                BizCheckUtil.checkNotBlank((String)deleteRequest.getId(), "id不能为空");
                BizCheckUtil.checkNotBlank((String)deleteRequest.getModifierId(),"操作人不能为空");
                BizCheckUtil.checkNotBlank(deleteRequest.getModifierType(),"操作人类型不能为空");
            }
            @Override
            public void executeService() {
                BaseResponse<Integer> placementThroughTrainApplyInfoResponse = placementThroughTrainApplyInfoConsumer.deletePlacementThroughTrainApplyInfo(deleteRequest);
                BeanUtil.copyProperties(placementThroughTrainApplyInfoResponse, baseResponse);
            }
            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.PLACEMENT_THROUGH_TRAIN_APPLY_INFO_DELETE_LOGICALLY;
            }
        });
        return baseResponse;
    }
}
